<?php
namespace app\index\controller;
use think\View;
use think\Db;
use think\Controller;
class Index extends Controller
{
    /**首页*/
    public function index()
    {
        $path = 'index';
        $laws = Db::query('select * from think_article where cate_id = 5  && status = 1 order by  update_time desc limit 8');
        $patent = Db::query('select * from think_article where cate_id = 1  && status = 1 order by  update_time desc limit 6');
        $agent  = Db::query('select * from think_article where cate_id = 2  && status = 1 order by  update_time desc limit 6');
        $register = Db::query('select * from think_article where cate_id = 4  && status = 1 order by  update_time desc limit 6');
        $news = Db::query('select * from think_article where cate_id = 3  && status = 1 order by  update_time desc limit 6');
        $exhibition = Db::query('select * from think_article where cate_id = 8  && status = 1 order by  update_time desc limit 6');
        $exhibition2 = Db::query('select * from think_article where cate_id = 9  && status = 1 order by  update_time desc limit 6');
        $exhibition3 = Db::query('select * from think_article where cate_id = 10  && status = 1 order by  update_time desc limit 6');
        $exhibition4 = Db::query('select * from think_article where cate_id = 11  && status = 1 order by  update_time desc limit 6');
        $pic = Db::query('select * from think_about where id=2');
        $ad = Db::query('select * from think_ad where status=1&&closed!=1');
        $number = Db::query('select * from think_ad where status=1&&closed !=1');
        $contact = Db::query('select * from think_contact');
        $mien = Db::query('select * from think_article where cate_id = 7  && status = 1 order by  update_time desc limit 6');
        $problem = Db::query('select * from think_article where cate_id = 6  && status = 1 order by  update_time desc limit 4');
        $a =0;
        foreach ($problem as $key=>$val){
            $problem[$key]['id'] = $a + 1;
            $a++;
        }
        foreach ($patent as $key=>$val){
            $patent[$key]['title'] = mb_substr($val['title'],0,18,'UTF-8');
        }
        foreach ($agent as $key=>$val){
            $agent[$key]['title'] = mb_substr($val['title'],0,18,'UTF-8');
        }
        foreach ($register as $key=>$val){
            $register[$key]['title'] = mb_substr($val['title'],0,18,'UTF-8');
        }
        foreach ($register as $key=>$val){
            $register[$key]['title'] = mb_substr($val['title'],0,18,'UTF-8');
        }

        $view = new View();
        $view->assign('ad', $ad);
        $view->assign('number', $number);
        $view->assign('path', $path);
        $view->assign('laws', $laws);
        $view->assign('patent', $patent);
        $view->assign('agent', $agent);
        $view->assign('register', $register);
        $view->assign('news', $news);
        $view->assign('pic', $pic);
        $view->assign('contact', $contact);
        $view->assign('exhibition', $exhibition);
        $view->assign('exhibition2', $exhibition2);
        $view->assign('exhibition3', $exhibition3);
        $view->assign('exhibition4', $exhibition4);
        $view->assign('mien', $mien);
        $view->assign('problem', $problem);
        return $view->fetch();
    }

    public function patent()
    {
        /**新闻中心1*/
        $path = 'patent';
        $id = input('id');
        if (!$id) {
            $id = 1;
        }
        $contact = Db::query('select * from think_contact');

        $type = Db::query('select * from think_category ');
        $warning = Db::query('select * from think_warning ');
        $article = Db::query('select * from think_article where status = 1 && cate_id= ? order by  update_time desc', [$id]);
        $about = Db::query('select * from think_about where id=1');
        $cate = Db::query('select * from think_article_cate  where id = ?', [$id]);
        $ad = Db::query('select * from think_ad ');
        $number = Db::query('select * from think_ad ');
        $view = new View();
        $view->assign('type', $type);
        $view->assign('warning', $warning);
        $view->assign('article', $article);
        $view->assign('about', $about);
        $view->assign('cate', $cate);
        $view->assign('ad', $ad);
        $view->assign('number', $number);
        $view->assign('path', $path);

        $view->assign('contact', $contact);
        return $view->fetch();
    }
    public function show_patent()
    {
        /**新闻详情页*/
        $contact = Db::query('select * from think_contact');
        $id = input('id');
        $path = ' ';
        $type = Db::query('select * from think_category ');
        $warning = Db::query('select * from think_warning ');
        $article = Db::query('select * from think_article where id = ?', [$id]);
        $about = Db::query('select * from think_about where id=1');
        $ad = Db::query('select * from think_ad ');
        $number = Db::query('select * from think_ad ');
        $cate = Db::query('select * from think_category ');
        $view = new View();
        $view->assign('type', $type);
        $view->assign('warning', $warning);
        $view->assign('article', $article);
        $view->assign('about', $about);
        $view->assign('ad', $ad);
        $view->assign('number', $number);
        $view->assign('path', $path);
        $view->assign('cate', $cate);
        $view->assign('contact', $contact);
        return $view->fetch();
    }

    public function have()
    {
        /**自有商标转让*/
        $path = 'have';
        $type = Db::query('select * from think_category ');
        $warning = Db::query('select * from think_warning ');
//        $have =  Db::query('select * from think_auditing  where shows = 1 && whetherown=1');
        $about = Db::query('select * from think_about where id=1');
        $cate = Db::query('select * from think_category ');

        $Nowpage = input('page') ? input('page') : 1;
        $limits = 16;// 获取总条数
        $count = Db::name('auditing')->where('shows = 1 and whetherown =1 ')->count();//计算总页面
        $allpage = intval(ceil($count / $limits));
        $x = ($Nowpage - 1) * $limits;
        $limit = "limit " . $x . "," . $limits;
        $have = Db::query('select * from think_auditing  where shows = 1 && whetherown =1 ' . $limit);
        if (request()->isAjax()) {
            return json($have);
        }
        $page = array(
            'nowpage' => $Nowpage,
            'allpage' => $allpage + 1,
        );

        $view = new View();
        $view->assign('type', $type);
        $view->assign('warning', $warning);
        $view->assign('have', $have);
        $view->assign('path', $path);
        $view->assign('about', $about);
        $view->assign('cate', $cate);
        $view->assign('page', $page);
        $view->assign('allpage', $allpage);
        $view->assign('nowpage', $Nowpage);
        return $view->fetch();
    }

    public function haves()
    {

        $Nowpage = input('page') ? input('page') : 1;
        $limits = 16;// 获取总条数
        $count = Db::name('auditing')->where('shows = 1 and whetherown =1 ')->count();//计算总页面
        $allpage = intval(ceil($count / $limits));
        $x = ($Nowpage - 1) * $limits;
        $limit = "limit " . $x . "," . $limits;
        $have = Db::query('select * from think_auditing  where shows = 1 && whetherown=1 ' . $limit);
        return json(['code' => 1, 'count' => $allpage, 'data' => $have]);

    }

    public function trademark()
    {
        /**商标超市*/
        $path = 'trademark';
        $type = Db::query('select * from think_category ');
        $warning = Db::query('select * from think_warning ');

        $Nowpage = input('page') ? input('page') : 1;
        $limits = 16;// 获取总条数
        $count = Db::name('auditing')->where('shows = 1 and whetherown !=0 ')->count();//计算总页面
        $allpage = intval(ceil($count / $limits));
        $x = ($Nowpage - 1) * $limits;
        $limit = "limit " . $x . "," . $limits;
        $trademark = Db::query('select * from think_auditing  where shows = 1 && whetherown!=0 ' . $limit);

        $ad = Db::query('select * from think_ad ');
        $number = Db::query('select * from think_ad ');
        $about = Db::query('select * from think_about where id=1');
        $cate = Db::query('select * from think_category ');

        if (request()->isAjax()) {
            return json($trademark);
        }
        $page = array(
            'nowpage' => $Nowpage,
            'allpage' => $allpage + 1,
        );


        $view = new View();
        $view->assign('type', $type);
        $view->assign('warning', $warning);
        $view->assign('trademark', $trademark);
        $view->assign('ad', $ad);
        $view->assign('number', $number);
        $view->assign('path', $path);
        $view->assign('about', $about);
        $view->assign('cate', $cate);

        $view->assign('page', $page); //当前页
        $view->assign('allpage', $allpage);
        $view->assign('nowpage', $Nowpage);
        return $view->fetch();
    }

}